package logic;

import java.sql.SQLException;

import ui.MessagePopUp;

/** Represents a deposit ATM transaction,
 * extending Transaction
 * @author Matthias
 * 
 */
public class Deposit extends Transaction {
	
	/** amount to deposit **/
	private double amount; 
	 
	/** Invokes the overridden superclass's constructor perform
	 * @param perform
	 */
	public Deposit (PerformTransactions perform) {
		super(perform);	
	} 
	
	/** takes action from Transaction and corresponding from PerformTransactions
	 * @see logic.Transaction#execute()
	 */
	@Override
	public void execute() {

		// input gets registered as amount
		amount = getClassPerform().getClassATM().getClassScreen().getAccDeposit().getInputDepositAmount();

		try {
			// credit account to reflect the deposit
			getClassPerform().getClassATM().getClassBdbAccSQL().creditAccSQL(getAccNr(), amount);
		} catch (SQLException e) {
			String text = "No valid envelope received. Please try again";
			new MessagePopUp().setError(text);
		}
	}

} // end class Deposit